package com.purong.purong.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.purong.purong.R;
import com.purong.purong.bean.SearchValueBean;
import com.purong.purong.util.CommonUtil;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout;

import java.util.List;

/**
 * Created by Administrator on 2016/8/29.
 */
public class CreditSearchMoreAdapter extends TagAdapter {
    private List<SearchValueBean> tagList;;
    private Context mContext;
    private TagFlowLayout mflowLayout;
    private OnSpecClickListener mListener;
    public CreditSearchMoreAdapter(Context context, TagFlowLayout flowLayout, List<SearchValueBean> list){
        super(list);
        this.tagList=list;
        this.mContext=context;
        this.mflowLayout=flowLayout;
    }
    public void setOnSpecClickListener(OnSpecClickListener listener){
        this.mListener=listener;
    }
    @Override
    public View getView(FlowLayout parent, final int position, Object o) {
        View view= LayoutInflater.from(mContext).inflate(R.layout.credit_search_more_tag,mflowLayout,false);
        TextView tv=(TextView) view.findViewById(R.id.search_tag);
        tv.setText(tagList.get(position).getTitle());
        if (tagList.get(position).isCheckTmp()){
            tv.setBackgroundResource(R.drawable.blue_radius3_bg);
            tv.setTextColor(mContext.getResources().getColor(R.color.white));
        }else {
            tv.setBackgroundResource(R.drawable.gray_radius3_bg);
            tv.setTextColor(mContext.getResources().getColor(R.color.text_dark_gray));
        }

        tv.setPadding(CommonUtil.dip2px(mContext,16), CommonUtil.dip2px(mContext,6),CommonUtil.dip2px(mContext,16),CommonUtil.dip2px(mContext,6));
        tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                for (int i = 0; i <tagList.size() ; i++) {
                    if (tagList.get(i).getItem().equals(tagList.get(position).getItem())){
                        tagList.get(i).setCheckTmp(!tagList.get(i).isCheckTmp());

                    }else {
                        tagList.get(i).setCheckTmp(false);

                    }
                }
                notifyDataChanged();

            }
        });

        return tv;
    }
    public interface OnSpecClickListener{
        void onCheck(int position);
    }
}
